
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>函数 · JavaScript学习</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Veng">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="函数的扩展.html" />
    
    
    <link rel="prev" href="Symbol.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="基础.html">
            
                <a href="基础.html">
            
                    
                    基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="变量.html">
            
                <a href="变量.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="let和const命令.html">
            
                <a href="let和const命令.html">
            
                    
                    let和const命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="数值.html">
            
                <a href="数值.html">
            
                    
                    数值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="字符串.html">
            
                <a href="字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="对象.html">
            
                <a href="对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="数组.html">
            
                <a href="数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="Symbol.html">
            
                <a href="Symbol.html">
            
                    
                    Symbol
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.8" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.8.1" data-path="函数的扩展.html">
            
                <a href="函数的扩展.html">
            
                    
                    函数的扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.2" data-path="变量的解构赋值.html">
            
                <a href="变量的解构赋值.html">
            
                    
                    变量作用域与解构赋值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.3" data-path="函数3.html">
            
                <a href="函数3.html">
            
                    
                    方法函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4" data-path="高阶函数.html">
            
                <a href="高阶函数.html">
            
                    
                    高阶函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.8.4.1" data-path="map-reduce.html">
            
                <a href="map-reduce.html">
            
                    
                    map/reduce
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.2" data-path="filter.html">
            
                <a href="filter.html">
            
                    
                    filter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.3" data-path="sort.html">
            
                <a href="sort.html">
            
                    
                    sort
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.4" data-path="array其他方法.html">
            
                <a href="array其他方法.html">
            
                    
                    array其他方法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.8.5" data-path="闭包.html">
            
                <a href="闭包.html">
            
                    
                    闭包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.6" data-path="箭头函数.html">
            
                <a href="箭头函数.html">
            
                    
                    箭头函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.7" data-path="../浏览器/Promise.html">
            
                <a href="../浏览器/Promise.html">
            
                    
                    Promise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.8" data-path="generator.html">
            
                <a href="generator.html">
            
                    
                    generator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.9" data-path="async.html">
            
                <a href="async.html">
            
                    
                    async
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="标准对象.html">
            
                <a href="标准对象.html">
            
                    
                    标准对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.9.1" data-path="SetMap.html">
            
                <a href="SetMap.html">
            
                    
                    Set,Map
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.2" data-path="Date.html">
            
                <a href="Date.html">
            
                    
                    Date
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.3" data-path="Math.html">
            
                <a href="Math.html">
            
                    
                    Math
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.4" data-path="Proxy.html">
            
                <a href="Proxy.html">
            
                    
                    Proxy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.5" data-path="RepExp.html">
            
                <a href="RepExp.html">
            
                    
                    正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.6" data-path="正则表达式.html">
            
                <a href="正则表达式.html">
            
                    
                    正则表达式别篇
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.7" data-path="json.html">
            
                <a href="json.html">
            
                    
                    JSON
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="面向对象编程.html">
            
                <a href="面向对象编程.html">
            
                    
                    面向对象编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.10.1" data-path="对象的扩展.html">
            
                <a href="对象的扩展.html">
            
                    
                    对象的扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.2" data-path="创建对象.html">
            
                <a href="创建对象.html">
            
                    
                    创建对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.3" data-path="原型继承.html">
            
                <a href="原型继承.html">
            
                    
                    原型继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.4" data-path="class继承.html">
            
                <a href="class继承.html">
            
                    
                    class继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.5" data-path="模块化Module.html">
            
                <a href="模块化Module.html">
            
                    
                    模块化Module
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="异常处理.html">
            
                <a href="异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="编程风格.html">
            
                <a href="编程风格.html">
            
                    
                    编程风格
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../js扩展/js扩展.html">
            
                <a href="../js扩展/js扩展.html">
            
                    
                    js 扩展
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../js扩展/字符串.html">
            
                <a href="../js扩展/字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../浏览器/浏览器.html">
            
                <a href="../浏览器/浏览器.html">
            
                    
                    浏览器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../浏览器/浏览器对象.html">
            
                <a href="../浏览器/浏览器对象.html">
            
                    
                    浏览器对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../浏览器/操作DOM.html">
            
                <a href="../浏览器/操作DOM.html">
            
                    
                    操作DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../浏览器/更新DOM.html">
            
                <a href="../浏览器/更新DOM.html">
            
                    
                    更新DOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../浏览器/插入DOM.html">
            
                <a href="../浏览器/插入DOM.html">
            
                    
                    插入DOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="../浏览器/删除DOM.html">
            
                <a href="../浏览器/删除DOM.html">
            
                    
                    删除DOM
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../浏览器/DOM事件.html">
            
                <a href="../浏览器/DOM事件.html">
            
                    
                    DOM事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../浏览器/操作表单.html">
            
                <a href="../浏览器/操作表单.html">
            
                    
                    操作表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../浏览器/操作文件.html">
            
                <a href="../浏览器/操作文件.html">
            
                    
                    操作文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../浏览器/AJAX.html">
            
                <a href="../浏览器/AJAX.html">
            
                    
                    AJAX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../浏览器/Canvas.html">
            
                <a href="../浏览器/Canvas.html">
            
                    
                    Canvas
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Jquery/jquery.html">
            
                <a href="../Jquery/jquery.html">
            
                    
                    Jquery
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Jquery/选择器.html">
            
                <a href="../Jquery/选择器.html">
            
                    
                    选择器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1.1" data-path="../Jquery/层级选择器.html">
            
                <a href="../Jquery/层级选择器.html">
            
                    
                    层级选择器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.2" data-path="../Jquery/查找和过滤.html">
            
                <a href="../Jquery/查找和过滤.html">
            
                    
                    查找和过滤
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Jquery/操作DOM.html">
            
                <a href="../Jquery/操作DOM.html">
            
                    
                    操作DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.2.1" data-path="../Jquery/修改DOM结构.html">
            
                <a href="../Jquery/修改DOM结构.html">
            
                    
                    修改DOM结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Jquery/事件.html">
            
                <a href="../Jquery/事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Jquery/动画.html">
            
                <a href="../Jquery/动画.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Jquery/AJAX.html">
            
                <a href="../Jquery/AJAX.html">
            
                    
                    AJAX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../Jquery/扩展.html">
            
                <a href="../Jquery/扩展.html">
            
                    
                    扩展
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../nodejs/nodejs.html">
            
                <a href="../nodejs/nodejs.html">
            
                    
                    Nodejs
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../nodejs/模块.html">
            
                <a href="../nodejs/模块.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../nodejs/path.html">
            
                <a href="../nodejs/path.html">
            
                    
                    path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../nodejs/文件操作.html">
            
                <a href="../nodejs/文件操作.html">
            
                    
                    文件操作 fs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../nodejs/流Stream.html">
            
                <a href="../nodejs/流Stream.html">
            
                    
                    流Stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../nodejs/zlib压缩解压缩.html">
            
                <a href="../nodejs/zlib压缩解压缩.html">
            
                    
                    zlib压缩解压缩
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../nodejs/net网络.html">
            
                <a href="../nodejs/net网络.html">
            
                    
                    net网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../nodejs/http.html">
            
                <a href="../nodejs/http.html">
            
                    
                    http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../nodejs/express框架.html">
            
                <a href="../nodejs/express框架.html">
            
                    
                    express框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../nodejs/process进程.html">
            
                <a href="../nodejs/process进程.html">
            
                    
                    process 进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../nodejs/child_process.html">
            
                <a href="../nodejs/child_process.html">
            
                    
                    child_process
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../nodejs/os.html">
            
                <a href="../nodejs/os.html">
            
                    
                    os-操作系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../react/react.html">
            
                <a href="../react/react.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >函数</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x51FD;&#x6570;">&#x51FD;&#x6570;</h1>
<h3 id="&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;">&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;</h3>
<p>JavaScript &#x6709;&#x4E09;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<h4 id="function-&#x547D;&#x4EE4;">function &#x547D;&#x4EE4;</h4>
<p><code>function</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x7684;&#x4EE3;&#x7801;&#x533A;&#x5757;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x3002;<code>function</code>&#x547D;&#x4EE4;&#x540E;&#x9762;&#x662F;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x51FD;&#x6570;&#x540D;&#x540E;&#x9762;&#x662F;&#x4E00;&#x5BF9;&#x5706;&#x62EC;&#x53F7;&#xFF0C;&#x91CC;&#x9762;&#x662F;&#x4F20;&#x5165;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;&#x51FD;&#x6570;&#x4F53;&#x653E;&#x5728;&#x5927;&#x62EC;&#x53F7;&#x91CC;&#x9762;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">print</span>(<span class="hljs-params">s</span>) </span>{
  <span class="hljs-built_in">console</span>.log(s);
}
</code></pre>
<h4 id="&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;">&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;</h4>
<p>&#x9664;&#x4E86;&#x7528;<code>function</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x51FD;&#x6570;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#x7684;&#x5199;&#x6CD5;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> print = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">s</span>) </span>{
  <span class="hljs-built_in">console</span>.log(s);
};
</code></pre>
<p>&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x5C06;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;&#x3002;&#x8FD9;&#x65F6;&#xFF0C;&#x8FD9;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x53C8;&#x79F0;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;Function Expression&#xFF09;&#xFF0C;&#x56E0;&#x4E3A;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x7684;&#x7B49;&#x53F7;&#x53F3;&#x4FA7;&#x53EA;&#x80FD;&#x653E;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<p>&#x91C7;&#x7528;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x65F6;&#xFF0C;<code>function</code>&#x547D;&#x4EE4;&#x540E;&#x9762;&#x4E0D;&#x5E26;&#x6709;&#x51FD;&#x6570;&#x540D;&#x3002;&#x5982;&#x679C;&#x52A0;&#x4E0A;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x8BE5;&#x51FD;&#x6570;&#x540D;&#x53EA;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x6709;&#x6548;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5916;&#x90E8;&#x65E0;&#x6548;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> print = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">x</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> x);
};

x
<span class="hljs-comment">// ReferenceError: x is not defined</span>

print()
<span class="hljs-comment">// function</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5728;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#xFF0C;&#x52A0;&#x5165;&#x4E86;&#x51FD;&#x6570;&#x540D;<code>x</code>&#x3002;&#x8FD9;&#x4E2A;<code>x</code>&#x53EA;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x53EF;&#x7528;&#xFF0C;&#x6307;&#x4EE3;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x672C;&#x8EAB;&#xFF0C;&#x5176;&#x4ED6;&#x5730;&#x65B9;&#x90FD;&#x4E0D;&#x53EF;&#x7528;&#x3002;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x7684;&#x7528;&#x5904;&#x6709;&#x4E24;&#x4E2A;&#xFF0C;&#x4E00;&#x662F;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x8C03;&#x7528;&#x81EA;&#x8EAB;&#xFF0C;&#x4E8C;&#x662F;&#x65B9;&#x4FBF;&#x9664;&#x9519;&#xFF08;&#x9664;&#x9519;&#x5DE5;&#x5177;&#x663E;&#x793A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x6808;&#x65F6;&#xFF0C;&#x5C06;&#x663E;&#x793A;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x800C;&#x4E0D;&#x518D;&#x663E;&#x793A;&#x8FD9;&#x91CC;&#x662F;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#xFF09;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x5F62;&#x5F0F;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x4E5F;&#x975E;&#x5E38;&#x5E38;&#x89C1;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{};
</code></pre>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x51FD;&#x6570;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x9700;&#x8981;&#x5728;&#x8BED;&#x53E5;&#x7684;&#x7ED3;&#x5C3E;&#x52A0;&#x4E0A;&#x5206;&#x53F7;&#xFF0C;&#x8868;&#x793A;&#x8BED;&#x53E5;&#x7ED3;&#x675F;&#x3002;&#x800C;&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;&#x5728;&#x7ED3;&#x5C3E;&#x7684;&#x5927;&#x62EC;&#x53F7;&#x540E;&#x9762;&#x4E0D;&#x7528;&#x52A0;&#x5206;&#x53F7;&#x3002;&#x603B;&#x7684;&#x6765;&#x8BF4;&#xFF0C;&#x8FD9;&#x4E24;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5DEE;&#x522B;&#x5F88;&#x7EC6;&#x5FAE;&#xFF0C;&#x53EF;&#x4EE5;&#x8FD1;&#x4F3C;&#x8BA4;&#x4E3A;&#x662F;&#x7B49;&#x4EF7;&#x7684;&#x3002;</p>
<h4 id="function-&#x6784;&#x9020;&#x51FD;&#x6570;">Function &#x6784;&#x9020;&#x51FD;&#x6570;</h4>
<p>&#x7B2C;&#x4E09;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x662F;<code>Function</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> add = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(
  <span class="hljs-string">&apos;x&apos;</span>,
  <span class="hljs-string">&apos;y&apos;</span>,
  <span class="hljs-string">&apos;return x + y&apos;</span>
);

<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">return</span> x + y;
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Function</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x63A5;&#x53D7;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x9664;&#x4E86;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;<code>add</code>&#x51FD;&#x6570;&#x7684;&#x201C;&#x51FD;&#x6570;&#x4F53;&#x201D;&#xFF0C;&#x5176;&#x4ED6;&#x53C2;&#x6570;&#x90FD;&#x662F;<code>add</code>&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x603B;&#x7684;&#x6765;&#x8BF4;&#xFF0C;&#x8FD9;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x975E;&#x5E38;&#x4E0D;&#x76F4;&#x89C2;&#xFF0C;&#x51E0;&#x4E4E;&#x65E0;&#x4EBA;&#x4F7F;&#x7528;&#x3002;</p>
<h3 id="&#x51FD;&#x6570;&#x7684;&#x91CD;&#x590D;&#x58F0;&#x660E;">&#x51FD;&#x6570;&#x7684;&#x91CD;&#x590D;&#x58F0;&#x660E;</h3>
<p>&#x5982;&#x679C;&#x540C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x88AB;&#x591A;&#x6B21;&#x58F0;&#x660E;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x58F0;&#x660E;&#x5C31;&#x4F1A;&#x8986;&#x76D6;&#x524D;&#x9762;&#x7684;&#x58F0;&#x660E;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
}
f() <span class="hljs-comment">// 2</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
}
f() <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x540E;&#x4E00;&#x6B21;&#x7684;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x8986;&#x76D6;&#x4E86;&#x524D;&#x9762;&#x4E00;&#x6B21;&#x3002;&#x800C;&#x4E14;&#xFF0C;&#x7531;&#x4E8E;&#x51FD;&#x6570;&#x540D;&#x7684;&#x63D0;&#x5347;&#xFF0C;&#x524D;&#x4E00;&#x6B21;&#x58F0;&#x660E;&#x5728;&#x4EFB;&#x4F55;&#x65F6;&#x5019;&#x90FD;&#x662F;&#x65E0;&#x6548;&#x7684;&#xFF0C;&#x8FD9;&#x4E00;&#x70B9;&#x8981;&#x7279;&#x522B;&#x6CE8;&#x610F;&#x3002;</p>
<h3 id="&#x51FD;&#x6570;&#x540D;&#x7684;&#x63D0;&#x5347;">&#x51FD;&#x6570;&#x540D;&#x7684;&#x63D0;&#x5347;</h3>
<p>JavaScript &#x5F15;&#x64CE;&#x5C06;&#x51FD;&#x6570;&#x540D;&#x89C6;&#x540C;&#x53D8;&#x91CF;&#x540D;&#xFF0C;&#x6240;&#x4EE5;&#x91C7;&#x7528;<code>function</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x6574;&#x4E2A;&#x51FD;&#x6570;&#x4F1A;&#x50CF;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#x4E00;&#x6837;&#xFF0C;&#x88AB;&#x63D0;&#x5347;&#x5230;&#x4EE3;&#x7801;&#x5934;&#x90E8;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-js">f();

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p>&#x8868;&#x9762;&#x4E0A;&#xFF0C;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x597D;&#x50CF;&#x5728;&#x58F0;&#x660E;&#x4E4B;&#x524D;&#x5C31;&#x8C03;&#x7528;&#x4E86;&#x51FD;&#x6570;<code>f</code>&#x3002;&#x4F46;&#x662F;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x7531;&#x4E8E;&#x201C;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#x201D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x88AB;&#x63D0;&#x5347;&#x5230;&#x4E86;&#x4EE3;&#x7801;&#x5934;&#x90E8;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5728;&#x8C03;&#x7528;&#x4E4B;&#x524D;&#x5DF2;&#x7ECF;&#x58F0;&#x660E;&#x4E86;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x91C7;&#x7528;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#xFF0C;JavaScript &#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<p>&#x8868;&#x9762;&#x4E0A;&#xFF0C;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x597D;&#x50CF;&#x5728;&#x58F0;&#x660E;&#x4E4B;&#x524D;&#x5C31;&#x8C03;&#x7528;&#x4E86;&#x51FD;&#x6570;<code>f</code>&#x3002;&#x4F46;&#x662F;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x7531;&#x4E8E;&#x201C;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#x201D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x88AB;&#x63D0;&#x5347;&#x5230;&#x4E86;&#x4EE3;&#x7801;&#x5934;&#x90E8;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5728;&#x8C03;&#x7528;&#x4E4B;&#x524D;&#x5DF2;&#x7ECF;&#x58F0;&#x660E;&#x4E86;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x91C7;&#x7528;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#xFF0C;JavaScript &#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-js">f();
<span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{};
<span class="hljs-comment">// TypeError: undefined is not a function</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x7B49;&#x540C;&#x4E8E;&#x4E0B;&#x9762;&#x7684;&#x5F62;&#x5F0F;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> f;
f();
f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7B2C;&#x4E8C;&#x884C;&#xFF0C;&#x8C03;&#x7528;<code>f</code>&#x7684;&#x65F6;&#x5019;&#xFF0C;<code>f</code>&#x53EA;&#x662F;&#x88AB;&#x58F0;&#x660E;&#x4E86;&#xFF0C;&#x8FD8;&#x6CA1;&#x6709;&#x88AB;&#x8D4B;&#x503C;&#xFF0C;&#x7B49;&#x4E8E;<code>undefined</code>&#xFF0C;&#x6240;&#x4EE5;&#x4F1A;&#x62A5;&#x9519;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5982;&#x679C;&#x540C;&#x65F6;&#x91C7;&#x7528;<code>function</code>&#x547D;&#x4EE4;&#x548C;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x58F0;&#x660E;&#x540C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x6700;&#x540E;&#x603B;&#x662F;&#x91C7;&#x7528;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x7684;&#x5B9A;&#x4E49;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;1&apos;</span>);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;2&apos;</span>);
}

f() <span class="hljs-comment">// 1</span>
</code></pre>
<h2 id="&#x51FD;&#x6570;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;">&#x51FD;&#x6570;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;</h2>
<h3 id="name&#x5C5E;&#x6027;">name&#x5C5E;&#x6027;</h3>
<p>&#x51FD;&#x6570;&#x7684;<code>name</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;&#x51FD;&#x6570;&#x7684;&#x540D;&#x5B57;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params"></span>) </span>{}
f1.name <span class="hljs-comment">// &quot;f1&quot;</span>
</code></pre>
<p>&#x5982;&#x679C;&#x662F;&#x901A;&#x8FC7;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#x5B9A;&#x4E49;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;<code>name</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;&#x53D8;&#x91CF;&#x540D;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> f2 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
f2.name <span class="hljs-comment">// &quot;f2&quot;</span>
</code></pre>
<p>&#x4F46;&#x662F;&#xFF0C;&#x4E0A;&#x9762;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x53EA;&#x6709;&#x5728;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x65F6;&#x624D;&#x662F;&#x5982;&#x6B64;&#x3002;&#x5982;&#x679C;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x5177;&#x540D;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;<code>name</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;<code>function</code>&#x5173;&#x952E;&#x5B57;&#x4E4B;&#x540E;&#x7684;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x540D;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> f3 = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">myName</span>(<span class="hljs-params"></span>) </span>{};
f3.name <span class="hljs-comment">// &apos;myName&apos;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>f3.name</code>&#x8FD4;&#x56DE;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x540D;&#x5B57;&#x3002;&#x6CE8;&#x610F;&#xFF0C;&#x771F;&#x6B63;&#x7684;&#x51FD;&#x6570;&#x540D;&#x8FD8;&#x662F;<code>f3</code>&#xFF0C;&#x800C;<code>myName</code>&#x8FD9;&#x4E2A;&#x540D;&#x5B57;&#x53EA;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x53EF;&#x7528;&#x3002;</p>
<h3 id="length-&#x5C5E;&#x6027;">length &#x5C5E;&#x6027;</h3>
<p>&#x51FD;&#x6570;&#x7684;<code>length</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;&#x51FD;&#x6570;&#x9884;&#x671F;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#xFF0C;&#x5373;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x4E4B;&#x4E2D;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, b</span>) </span>{}
f.length <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5B9A;&#x4E49;&#x4E86;&#x7A7A;&#x51FD;&#x6570;<code>f</code>&#xFF0C;&#x5B83;&#x7684;<code>length</code>&#x5C5E;&#x6027;&#x5C31;&#x662F;&#x5B9A;&#x4E49;&#x65F6;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x3002;&#x4E0D;&#x7BA1;&#x8C03;&#x7528;&#x65F6;&#x8F93;&#x5165;&#x4E86;&#x591A;&#x5C11;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;<code>length</code>&#x5C5E;&#x6027;&#x59CB;&#x7EC8;&#x7B49;&#x4E8E;2&#x3002;</p>
<p>&#x9644;&#x52A0;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params">...rest</span>)</span>{}
<span class="hljs-built_in">console</span>.log(test.length); <span class="hljs-comment">//  0</span>
</code></pre>
<h3 id="tostring">toString()</h3>
<p>&#x51FD;&#x6570;&#x7684;<code>toString</code>&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5185;&#x5BB9;&#x662F;&#x51FD;&#x6570;&#x7684;&#x6E90;&#x7801;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">print</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;hello&quot;</span>);
}
<span class="hljs-built_in">console</span>.log(print.toString());
=&gt;
<span class="hljs-comment">/*
function print() {
    console.log(&quot;hello&quot;);
}
*/</span>
</code></pre>
<p>&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x6CE8;&#x91CA;&#x4E5F;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x3002;</p>
<h2 id="&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;">&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;</h2>
<p>&#x4F5C;&#x7528;&#x57DF;&#xFF08;scope&#xFF09;&#x6307;&#x7684;&#x662F;&#x53D8;&#x91CF;&#x5B58;&#x5728;&#x7684;&#x8303;&#x56F4;&#x3002;&#x5728; ES5 &#x7684;&#x89C4;&#x8303;&#x4E2D;&#xFF0C;JavaScript &#x53EA;&#x6709;&#x4E24;&#x79CD;&#x4F5C;&#x7528;&#x57DF;&#xFF1A;&#x4E00;&#x79CD;&#x662F;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x53D8;&#x91CF;&#x5728;&#x6574;&#x4E2A;&#x7A0B;&#x5E8F;&#x4E2D;&#x4E00;&#x76F4;&#x5B58;&#x5728;&#xFF0C;&#x6240;&#x6709;&#x5730;&#x65B9;&#x90FD;&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#xFF1B;&#x53E6;&#x4E00;&#x79CD;&#x662F;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x53D8;&#x91CF;&#x53EA;&#x5728;<strong>&#x51FD;&#x6570;</strong>&#x5185;&#x90E8;&#x5B58;&#x5728;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> v = <span class="hljs-number">1</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-keyword">var</span> v = <span class="hljs-number">2</span>;
  <span class="hljs-built_in">console</span>.log(v);
}

f() <span class="hljs-comment">// 2</span>
v <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4F46;&#x662F;&#x5982;&#x679C;&#x4E0D;&#x662F;&#x5728;&#x51FD;&#x6570;&#x4E2D;&#x5B9A;&#x4E49;&#xFF0C;&#x6BD4;&#x5982;&#x5728;if&#x5757;&#x4E2D;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x5747;&#x4F1A;&#x63D0;&#x5347;&#x5230;&#x5230;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
  <span class="hljs-keyword">var</span> x = <span class="hljs-number">5</span>;
}
<span class="hljs-built_in">console</span>.log(x);  <span class="hljs-comment">// 5</span>
</code></pre>
<h3 id="&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#x63D0;&#x5347;">&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#x63D0;&#x5347;</h3>
<p>&#x4E0E;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x4E00;&#x6837;&#xFF0C;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x90E8;&#x4E5F;&#x4F1A;&#x4EA7;&#x751F;&#x201C;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#x201D;&#x73B0;&#x8C61;&#x3002;<code>var</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x4E0D;&#x7BA1;&#x5728;&#x4EC0;&#x4E48;&#x4F4D;&#x7F6E;&#xFF0C;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#x90FD;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x5230;&#x51FD;&#x6570;&#x4F53;&#x7684;&#x5934;&#x90E8;&#x3002;</p>
<p>&#x5907;&#x6CE8;&#xFF1A;&#x53EF;&#x4EE5;&#x5F62;&#x8C61;&#x7684;&#x7C7B;&#x6BD4;&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x662F;&#x4E00;&#x4E2A;&#x65B0;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x8DDF;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x4E00;&#x6837;&#x3002;</p>
<h3 id="&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x7684;&#x4F5C;&#x7528;&#x57DF;">&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x7684;&#x4F5C;&#x7528;&#x57DF;</h3>
<p>&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x4E5F;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x3002;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4E0E;&#x53D8;&#x91CF;&#x4E00;&#x6837;&#xFF0C;&#x5C31;&#x662F;&#x5176;&#x58F0;&#x660E;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x4E0E;&#x5176;&#x8FD0;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x65E0;&#x5173;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> x = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> a = <span class="hljs-number">2</span>;
  x();
}

f() <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x6B63;&#x662F;&#x8FD9;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x6784;&#x6210;&#x4E86;&#x201C;<a href="&#x95ED;&#x5305;.html">&#x95ED;&#x5305;</a>&#x201D;&#x3002;</p>
<h2 id="&#x53C2;&#x6570;">&#x53C2;&#x6570;</h2>
<h3 id="&#x53C2;&#x6570;&#x7684;&#x7701;&#x7565;">&#x53C2;&#x6570;&#x7684;&#x7701;&#x7565;</h3>
<p>&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4E0D;&#x662F;&#x5FC5;&#x9700;&#x7684;&#xFF0C;JavaScript &#x5141;&#x8BB8;&#x7701;&#x7565;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a;
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>) <span class="hljs-comment">// 1</span>
f(<span class="hljs-number">1</span>) <span class="hljs-comment">// 1</span>
f() <span class="hljs-comment">// undefined</span>

f.length <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x51FD;&#x6570;<code>f</code>&#x5B9A;&#x4E49;&#x4E86;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4F46;&#x662F;&#x8FD0;&#x884C;&#x65F6;&#x65E0;&#x8BBA;&#x63D0;&#x4F9B;&#x591A;&#x5C11;&#x4E2A;&#x53C2;&#x6570;&#xFF08;&#x6216;&#x8005;&#x4E0D;&#x63D0;&#x4F9B;&#x53C2;&#x6570;&#xFF09;&#xFF0C;JavaScript &#x90FD;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x3002;&#x7701;&#x7565;&#x7684;&#x53C2;&#x6570;&#x7684;&#x503C;&#x5C31;&#x53D8;&#x4E3A;<code>undefined</code>&#x3002;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x51FD;&#x6570;&#x7684;<code>length</code>&#x5C5E;&#x6027;&#x4E0E;&#x5B9E;&#x9645;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x65E0;&#x5173;&#xFF0C;&#x53EA;&#x53CD;&#x6620;&#x51FD;&#x6570;&#x9884;&#x671F;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x53EA;&#x7701;&#x7565;&#x9760;&#x524D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x800C;&#x4FDD;&#x7559;&#x9760;&#x540E;&#x7684;&#x53C2;&#x6570;&#x3002;&#x5982;&#x679C;&#x4E00;&#x5B9A;&#x8981;&#x7701;&#x7565;&#x9760;&#x524D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x53EA;&#x6709;&#x663E;&#x5F0F;&#x4F20;&#x5165;<code>undefined</code>&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a;
}

f( , <span class="hljs-number">1</span>) <span class="hljs-comment">// SyntaxError: Unexpected token ,(&#x2026;)</span>
f(<span class="hljs-literal">undefined</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// undefined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x7701;&#x7565;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<h3 id="&#x4F20;&#x9012;&#x65B9;&#x5F0F;">&#x4F20;&#x9012;&#x65B9;&#x5F0F;</h3>
<p>&#x51FD;&#x6570;&#x53C2;&#x6570;&#x5982;&#x679C;&#x662F;&#x539F;&#x59CB;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF08;&#x6570;&#x503C;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x5E03;&#x5C14;&#x503C;&#xFF09;&#xFF0C;&#x4F20;&#x9012;&#x65B9;&#x5F0F;&#x662F;&#x4F20;&#x503C;&#x4F20;&#x9012;&#xFF08;passes by value&#xFF09;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x4FEE;&#x6539;&#x53C2;&#x6570;&#x503C;&#xFF0C;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> p = <span class="hljs-number">2</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">p</span>) </span>{
  p = <span class="hljs-number">3</span>;
}
f(p);

p <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53D8;&#x91CF;<code>p</code>&#x662F;&#x4E00;&#x4E2A;&#x539F;&#x59CB;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;<code>f</code>&#x7684;&#x65B9;&#x5F0F;&#x662F;&#x4F20;&#x503C;&#x4F20;&#x9012;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#xFF0C;<code>p</code>&#x7684;&#x503C;&#x662F;&#x539F;&#x59CB;&#x503C;&#x7684;&#x62F7;&#x8D1D;&#xFF0C;&#x65E0;&#x8BBA;&#x600E;&#x4E48;&#x4FEE;&#x6539;&#xFF0C;&#x90FD;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x662F;&#x590D;&#x5408;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF08;&#x6570;&#x7EC4;&#x3001;&#x5BF9;&#x8C61;&#x3001;&#x5176;&#x4ED6;&#x51FD;&#x6570;&#xFF09;&#xFF0C;&#x4F20;&#x9012;&#x65B9;&#x5F0F;&#x662F;&#x4F20;&#x5740;&#x4F20;&#x9012;&#xFF08;pass by reference&#xFF09;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;&#x7684;&#x539F;&#x59CB;&#x503C;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x56E0;&#x6B64;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x6539;&#x53C2;&#x6570;&#xFF0C;&#x5C06;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> obj = { p: <span class="hljs-number">1</span> };

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">o</span>) </span>{
  o.p = <span class="hljs-number">2</span>;
}
f(obj);

obj.p <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;<code>f</code>&#x7684;&#x662F;&#x53C2;&#x6570;&#x5BF9;&#x8C61;<code>obj</code>&#x7684;&#x5730;&#x5740;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x6539;<code>obj</code>&#x7684;&#x5C5E;&#x6027;<code>p</code>&#xFF0C;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x6539;&#x7684;&#xFF0C;&#x4E0D;&#x662F;&#x53C2;&#x6570;&#x5BF9;&#x8C61;&#x7684;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x800C;&#x662F;&#x66FF;&#x6362;&#x6389;&#x6574;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x65F6;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> obj = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">o</span>) </span>{
  o = [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];
}
f(obj);

obj <span class="hljs-comment">// [1, 2, 3]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5728;&#x51FD;&#x6570;<code>f</code>&#x5185;&#x90E8;&#xFF0C;&#x53C2;&#x6570;&#x5BF9;&#x8C61;<code>obj</code>&#x88AB;&#x6574;&#x4E2A;&#x66FF;&#x6362;&#x6210;&#x53E6;&#x4E00;&#x4E2A;&#x503C;&#x3002;&#x8FD9;&#x65F6;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#xFF0C;&#x5F62;&#x5F0F;&#x53C2;&#x6570;&#xFF08;<code>o</code>&#xFF09;&#x7684;&#x503C;&#x5B9E;&#x9645;&#x662F;&#x53C2;&#x6570;<code>obj</code>&#x7684;&#x5730;&#x5740;&#xFF0C;&#x91CD;&#x65B0;&#x5BF9;<code>o</code>&#x8D4B;&#x503C;&#x5BFC;&#x81F4;<code>o</code>&#x6307;&#x5411;&#x53E6;&#x4E00;&#x4E2A;&#x5730;&#x5740;&#xFF0C;&#x4FDD;&#x5B58;&#x5728;&#x539F;&#x5730;&#x5740;&#x4E0A;&#x7684;&#x503C;&#x5F53;&#x7136;&#x4E0D;&#x53D7;&#x5F71;&#x54CD;&#x3002;</p>
<h3 id="&#x540C;&#x540D;&#x53C2;&#x6570;">&#x540C;&#x540D;&#x53C2;&#x6570;</h3>
<p>&#x5982;&#x679C;&#x6709;&#x540C;&#x540D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x53D6;&#x6700;&#x540E;&#x51FA;&#x73B0;&#x7684;&#x90A3;&#x4E2A;&#x503C;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, a</span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>) <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x6709;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E14;&#x53C2;&#x6570;&#x540D;&#x90FD;&#x662F;<code>a</code>&#x3002;&#x53D6;&#x503C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4EE5;&#x540E;&#x9762;&#x7684;<code>a</code>&#x4E3A;&#x51C6;&#xFF0C;&#x5373;&#x4F7F;&#x540E;&#x9762;&#x7684;<code>a</code>&#x6CA1;&#x6709;&#x503C;&#x6216;&#x88AB;&#x7701;&#x7565;&#xFF0C;&#x4E5F;&#x662F;&#x4EE5;&#x5176;&#x4E3A;&#x51C6;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, a</span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
}

f(<span class="hljs-number">1</span>) <span class="hljs-comment">// undefined</span>
</code></pre>
<h3 id="&#x5B9A;&#x4E49;&#x51FD;&#x6570;">&#x5B9A;&#x4E49;&#x51FD;&#x6570;</h3>
<p>&#x5728;JavaScript&#x4E2D;&#xFF0C;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">abs</span>(<span class="hljs-params">x</span>) </span>{
    <span class="hljs-keyword">if</span> (x &gt;= <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">return</span> x;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> -x;
    }
}
</code></pre>
<p>&#x8BF7;&#x6CE8;&#x610F;&#xFF0C;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x7684;&#x8BED;&#x53E5;&#x5728;&#x6267;&#x884C;&#x65F6;&#xFF0C;&#x4E00;&#x65E6;&#x6267;&#x884C;&#x5230;<code>return</code>&#x65F6;&#xFF0C;&#x51FD;&#x6570;&#x5C31;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#xFF0C;&#x5E76;&#x5C06;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x901A;&#x8FC7;&#x6761;&#x4EF6;&#x5224;&#x65AD;&#x548C;&#x5FAA;&#x73AF;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x975E;&#x5E38;&#x590D;&#x6742;&#x7684;&#x903B;&#x8F91;&#x3002;</p>
<p>&#x5982;&#x679C;&#x6CA1;&#x6709;<code>return</code>&#x8BED;&#x53E5;&#xFF0C;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x540E;&#x4E5F;&#x4F1A;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF0C;&#x53EA;&#x662F;&#x7ED3;&#x679C;&#x4E3A;<code>undefined</code>&#x3002;</p>
<p>&#x7531;&#x4E8E;JavaScript&#x7684;&#x51FD;&#x6570;&#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x4E0A;&#x8FF0;&#x5B9A;&#x4E49;&#x7684;<code>abs()</code>&#x51FD;&#x6570;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x51FD;&#x6570;&#x540D;<code>abs</code>&#x53EF;&#x4EE5;&#x89C6;&#x4E3A;&#x6307;&#x5411;&#x8BE5;&#x51FD;&#x6570;&#x7684;&#x53D8;&#x91CF;&#x3002;</p>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x7B2C;&#x4E8C;&#x79CD;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> abs = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">x</span>) </span>{
    <span class="hljs-keyword">if</span> (x &gt;= <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">return</span> x;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> -x;
    }
};
</code></pre>
<p>&#x5728;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x4E0B;&#xFF0C;<code>function (x) { ... }</code>&#x662F;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x6CA1;&#x6709;&#x51FD;&#x6570;&#x540D;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x4E86;&#x53D8;&#x91CF;<code>abs</code>&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x901A;&#x8FC7;&#x53D8;&#x91CF;<code>abs</code>&#x5C31;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x8BE5;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x4E0A;&#x8FF0;&#x4E24;&#x79CD;&#x5B9A;&#x4E49;<em>&#x5B8C;&#x5168;&#x7B49;&#x4EF7;</em>&#xFF0C;&#x6CE8;&#x610F;&#x7B2C;&#x4E8C;&#x79CD;&#x65B9;&#x5F0F;&#x6309;&#x7167;&#x5B8C;&#x6574;&#x8BED;&#x6CD5;&#x9700;&#x8981;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x672B;&#x5C3E;&#x52A0;&#x4E00;&#x4E2A;<code>;</code>&#xFF0C;&#x8868;&#x793A;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x7ED3;&#x675F;&#x3002;</p>
<h3 id="&#x8C03;&#x7528;&#x51FD;&#x6570;">&#x8C03;&#x7528;&#x51FD;&#x6570;</h3>
<p>&#x7531;&#x4E8E;JavaScript&#x5141;&#x8BB8;&#x4F20;&#x5165;&#x4EFB;&#x610F;&#x4E2A;&#x53C2;&#x6570;&#x800C;&#x4E0D;&#x5F71;&#x54CD;&#x8C03;&#x7528;&#xFF0C;&#x56E0;&#x6B64;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x6BD4;&#x5B9A;&#x4E49;&#x7684;&#x53C2;&#x6570;&#x591A;&#x4E5F;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#xFF0C;&#x867D;&#x7136;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5E76;&#x4E0D;&#x9700;&#x8981;&#x8FD9;&#x4E9B;&#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-javaScript">abs(<span class="hljs-number">10</span>, <span class="hljs-string">&apos;blablabla&apos;</span>); <span class="hljs-comment">// &#x8FD4;&#x56DE;10</span>
abs(<span class="hljs-number">-9</span>, <span class="hljs-string">&apos;haha&apos;</span>, <span class="hljs-string">&apos;hehe&apos;</span>, <span class="hljs-literal">null</span>); <span class="hljs-comment">// &#x8FD4;&#x56DE;9</span>
</code></pre>
<p>&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x6BD4;&#x5B9A;&#x4E49;&#x7684;&#x5C11;&#x4E5F;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#xFF1A;</p>
<pre><code class="lang-javascript">abs(); <span class="hljs-comment">// &#x8FD4;&#x56DE;NaN</span>
</code></pre>
<p>&#x6B64;&#x65F6;<code>abs(x)</code>&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;<code>x</code>&#x5C06;&#x6536;&#x5230;<code>undefined</code>&#xFF0C;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;&#x4E3A;<code>NaN</code>&#x3002;</p>
<p>&#x8981;&#x907F;&#x514D;&#x6536;&#x5230;<code>undefined</code>&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x68C0;&#x67E5;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">abs</span>(<span class="hljs-params">x</span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> x !== <span class="hljs-string">&apos;number&apos;</span>) {
        <span class="hljs-keyword">throw</span> <span class="hljs-string">&apos;Not a number&apos;</span>;
    }
    <span class="hljs-keyword">if</span> (x &gt;= <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">return</span> x;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> -x;
    }
}
</code></pre>
<h3 id="arguments">arguments</h3>
<p>JavaScript&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x514D;&#x8D39;&#x8D60;&#x9001;&#x7684;&#x5173;&#x952E;&#x5B57;<code>arguments</code>&#xFF0C;&#x5B83;&#x53EA;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x8D77;&#x4F5C;&#x7528;&#xFF0C;&#x5E76;&#x4E14;&#x6C38;&#x8FDC;&#x6307;&#x5411;&#x5F53;&#x524D;&#x51FD;&#x6570;&#x7684;&#x8C03;&#x7528;&#x8005;&#x4F20;&#x5165;&#x7684;&#x6240;&#x6709;&#x53C2;&#x6570;&#x3002;<code>arguments</code>&#x7C7B;&#x4F3C;<code>Array</code>&#x4F46;&#x5B83;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;<code>Array</code>&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">x</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;x = &apos;</span> + x); <span class="hljs-comment">// 10</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-built_in">arguments</span>.length; i++) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;arg &apos;</span> + i + <span class="hljs-string">&apos; = &apos;</span> + <span class="hljs-built_in">arguments</span>[i]); <span class="hljs-comment">// 10, 20, 30</span>
    }
}
foo(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>);
</code></pre>
<pre><code class="lang-shell">x = 10
arg 0 = 10
arg 1 = 20
arg 2 = 30
</code></pre>
<p>&#x5B9E;&#x9645;&#x4E0A;<code>arguments</code>&#x6700;&#x5E38;&#x7528;&#x4E8E;&#x5224;&#x65AD;&#x4F20;&#x5165;&#x53C2;&#x6570;&#x7684;&#x4E2A;&#x6570;&#x3002;&#x4F60;&#x53EF;&#x80FD;&#x4F1A;&#x770B;&#x5230;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// foo(a[, b], c)</span>
<span class="hljs-comment">// &#x63A5;&#x6536;2~3&#x4E2A;&#x53C2;&#x6570;&#xFF0C;b&#x662F;&#x53EF;&#x9009;&#x53C2;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x53EA;&#x4F20;2&#x4E2A;&#x53C2;&#x6570;&#xFF0C;b&#x9ED8;&#x8BA4;&#x4E3A;null&#xFF1A;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">a, b, c</span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">arguments</span>.length === <span class="hljs-number">2</span>) {
        <span class="hljs-comment">// &#x5B9E;&#x9645;&#x62FF;&#x5230;&#x7684;&#x53C2;&#x6570;&#x662F;a&#x548C;b&#xFF0C;c&#x4E3A;undefined</span>
        c = b; <span class="hljs-comment">// &#x628A;b&#x8D4B;&#x7ED9;c</span>
        b = <span class="hljs-literal">null</span>; <span class="hljs-comment">// b&#x53D8;&#x4E3A;&#x9ED8;&#x8BA4;&#x503C;</span>
    }
    <span class="hljs-comment">// ...</span>
}
</code></pre>
<h3 id="rest&#x53C2;&#x6570;">rest&#x53C2;&#x6570;</h3>
<p>&#x7531;&#x4E8E;JavaScript&#x51FD;&#x6570;&#x5141;&#x8BB8;&#x63A5;&#x6536;&#x4EFB;&#x610F;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E8E;&#x662F;&#x6211;&#x4EEC;&#x5C31;&#x4E0D;&#x5F97;&#x4E0D;&#x7528;<code>arguments</code>&#x6765;&#x83B7;&#x53D6;&#x6240;&#x6709;&#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">a, b</span>) </span>{
    <span class="hljs-keyword">var</span> i, rest = [];
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">arguments</span>.length &gt; <span class="hljs-number">2</span>) {
        <span class="hljs-keyword">for</span> (i = <span class="hljs-number">2</span>; i&lt;<span class="hljs-built_in">arguments</span>.length; i++) {
            rest.push(<span class="hljs-built_in">arguments</span>[i]);
        }
    }
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;a = &apos;</span> + a);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;b = &apos;</span> + b);
    <span class="hljs-built_in">console</span>.log(rest);
}
</code></pre>
<p>&#x4E3A;&#x4E86;&#x83B7;&#x53D6;&#x9664;&#x4E86;&#x5DF2;&#x5B9A;&#x4E49;&#x53C2;&#x6570;<code>a</code>&#x3001;<code>b</code>&#x4E4B;&#x5916;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x5F97;&#x4E0D;&#x7528;<code>arguments</code>&#xFF0C;&#x5E76;&#x4E14;&#x5FAA;&#x73AF;&#x8981;&#x4ECE;&#x7D22;&#x5F15;<code>2</code>&#x5F00;&#x59CB;&#x4EE5;&#x4FBF;&#x6392;&#x9664;&#x524D;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x5F88;&#x522B;&#x626D;&#xFF0C;&#x53EA;&#x662F;&#x4E3A;&#x4E86;&#x83B7;&#x5F97;&#x989D;&#x5916;&#x7684;<code>rest</code>&#x53C2;&#x6570;&#xFF0C;&#x6709;&#x6CA1;&#x6709;&#x66F4;&#x597D;&#x7684;&#x65B9;&#x6CD5;&#xFF1F;</p>
<p>ES6&#x6807;&#x51C6;&#x5F15;&#x5165;&#x4E86;rest&#x53C2;&#x6570;&#xFF0C;&#x4E0A;&#x9762;&#x7684;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x6539;&#x5199;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">a, b, ...rest</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;a = &apos;</span> + a);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;b = &apos;</span> + b);
    <span class="hljs-built_in">console</span>.log(rest);
}

foo(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>);
<span class="hljs-comment">// &#x7ED3;&#x679C;:</span>
<span class="hljs-comment">// a = 1</span>
<span class="hljs-comment">// b = 2</span>
<span class="hljs-comment">// Array [ 3, 4, 5 ]</span>

foo(<span class="hljs-number">1</span>);
<span class="hljs-comment">// &#x7ED3;&#x679C;:</span>
<span class="hljs-comment">// a = 1</span>
<span class="hljs-comment">// b = undefined</span>
<span class="hljs-comment">// Array []</span>
</code></pre>
<p>rest&#x53C2;&#x6570;&#x53EA;&#x80FD;&#x5199;&#x5728;&#x6700;&#x540E;&#xFF0C;&#x524D;&#x9762;&#x7528;<code>...</code>&#x6807;&#x8BC6;&#xFF0C;&#x4ECE;&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#x53EF;&#x77E5;&#xFF0C;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x5148;&#x7ED1;&#x5B9A;<code>a</code>&#x3001;<code>b</code>&#xFF0C;&#x591A;&#x4F59;&#x7684;&#x53C2;&#x6570;&#x4EE5;&#x6570;&#x7EC4;&#x5F62;&#x5F0F;&#x4EA4;&#x7ED9;&#x53D8;&#x91CF;<code>rest</code>&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x4E0D;&#x518D;&#x9700;&#x8981;<code>arguments</code>&#x6211;&#x4EEC;&#x5C31;&#x83B7;&#x53D6;&#x4E86;&#x5168;&#x90E8;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x8FDE;&#x6B63;&#x5E38;&#x5B9A;&#x4E49;&#x7684;&#x53C2;&#x6570;&#x90FD;&#x6CA1;&#x586B;&#x6EE1;&#xFF0C;&#x4E5F;&#x4E0D;&#x8981;&#x7D27;&#xFF0C;rest&#x53C2;&#x6570;&#x4F1A;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x7A7A;&#x6570;&#x7EC4;&#xFF08;&#x6CE8;&#x610F;&#x4E0D;&#x662F;<code>undefined</code>&#xFF09;&#x3002;</p>
<h3 id="&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;iife&#xFF09;">&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;IIFE&#xFF09;</h3>
<p>&#x5728; JavaScript &#x4E2D;&#xFF0C;&#x5706;&#x62EC;&#x53F7;<code>()</code>&#x662F;&#x4E00;&#x79CD;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x8DDF;&#x5728;&#x51FD;&#x6570;&#x540D;&#x4E4B;&#x540E;&#xFF0C;&#x8868;&#x793A;&#x8C03;&#x7528;&#x8BE5;&#x51FD;&#x6570;&#x3002;&#x6BD4;&#x5982;&#xFF0C;<code>print()</code>&#x5C31;&#x8868;&#x793A;&#x8C03;&#x7528;<code>print</code>&#x51FD;&#x6570;&#x3002;</p>
<p>&#x6709;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x4E4B;&#x540E;&#xFF0C;&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x8BE5;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x65F6;&#xFF0C;&#x4F60;&#x4E0D;&#x80FD;&#x5728;&#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49;&#x4E4B;&#x540E;&#x52A0;&#x4E0A;&#x5706;&#x62EC;&#x53F7;&#xFF0C;&#x8FD9;&#x4F1A;&#x4EA7;&#x751F;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }();
<span class="hljs-comment">// SyntaxError: Unexpected token (</span>
</code></pre>
<p>&#x4EA7;&#x751F;&#x8FD9;&#x4E2A;&#x9519;&#x8BEF;&#x7684;&#x539F;&#x56E0;&#x662F;&#xFF0C;<code>function</code>&#x8FD9;&#x4E2A;&#x5173;&#x952E;&#x5B57;&#x5373;&#x53EF;&#x4EE5;&#x5F53;&#x4F5C;&#x8BED;&#x53E5;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5F53;&#x4F5C;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<pre><code class="lang-JS"><span class="hljs-comment">// &#x8BED;&#x53E5;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}

<span class="hljs-comment">// &#x8868;&#x8FBE;&#x5F0F;</span>
<span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p>&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x89E3;&#x6790;&#x4E0A;&#x7684;&#x6B67;&#x4E49;&#xFF0C;JavaScript &#x5F15;&#x64CE;&#x89C4;&#x5B9A;&#xFF0C;&#x5982;&#x679C;<code>function</code>&#x5173;&#x952E;&#x5B57;&#x51FA;&#x73B0;&#x5728;&#x884C;&#x9996;&#xFF0C;&#x4E00;&#x5F8B;&#x89E3;&#x91CA;&#x6210;&#x8BED;&#x53E5;&#x3002;&#x56E0;&#x6B64;&#xFF0C;JavaScript &#x5F15;&#x64CE;&#x770B;&#x5230;&#x884C;&#x9996;&#x662F;<code>function</code>&#x5173;&#x952E;&#x5B57;&#x4E4B;&#x540E;&#xFF0C;&#x8BA4;&#x4E3A;&#x8FD9;&#x4E00;&#x6BB5;&#x90FD;&#x662F;&#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49;&#xFF0C;&#x4E0D;&#x5E94;&#x8BE5;&#x4EE5;&#x5706;&#x62EC;&#x53F7;&#x7ED3;&#x5C3E;&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x62A5;&#x9519;&#x4E86;&#x3002;</p>
<p>&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x4E0D;&#x8981;&#x8BA9;<code>function</code>&#x51FA;&#x73B0;&#x5728;&#x884C;&#x9996;&#xFF0C;&#x8BA9;&#x5F15;&#x64CE;&#x5C06;&#x5176;&#x7406;&#x89E3;&#x6210;&#x4E00;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x3002;&#x6700;&#x7B80;&#x5355;&#x7684;&#x5904;&#x7406;&#xFF0C;&#x5C31;&#x662F;&#x5C06;&#x5176;&#x653E;&#x5728;&#x4E00;&#x4E2A;&#x5706;&#x62EC;&#x53F7;&#x91CC;&#x9762;&#x3002;</p>
<pre><code class="lang-JS">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }());
<span class="hljs-comment">// &#x6216;&#x8005;</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> })();
</code></pre>
<p>&#x4E0A;&#x9762;&#x4E24;&#x79CD;&#x5199;&#x6CD5;&#x90FD;&#x662F;&#x4EE5;&#x5706;&#x62EC;&#x53F7;&#x5F00;&#x5934;&#xFF0C;&#x5F15;&#x64CE;&#x5C31;&#x4F1A;&#x8BA4;&#x4E3A;&#x540E;&#x9762;&#x8DDF;&#x7684;&#x662F;&#x4E00;&#x4E2A;&#x8868;&#x793A;&#x5F0F;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x8BED;&#x53E5;&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x907F;&#x514D;&#x4E86;&#x9519;&#x8BEF;&#x3002;&#x8FD9;&#x5C31;&#x53EB;&#x505A;&#x201C;&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x201D;&#xFF08;Immediately-Invoked Function Expression&#xFF09;&#xFF0C;&#x7B80;&#x79F0; IIFE&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x4E0A;&#x9762;&#x4E24;&#x79CD;&#x5199;&#x6CD5;&#x6700;&#x540E;&#x7684;&#x5206;&#x53F7;&#x90FD;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;&#x5982;&#x679C;&#x7701;&#x7565;&#x5206;&#x53F7;&#xFF0C;&#x9047;&#x5230;&#x8FDE;&#x7740;&#x4E24;&#x4E2A; IIFE&#xFF0C;&#x53EF;&#x80FD;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x62A5;&#x9519;</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }())
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }())
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x4E24;&#x884C;&#x4E4B;&#x95F4;&#x6CA1;&#x6709;&#x5206;&#x53F7;&#xFF0C;JavaScript &#x4F1A;&#x5C06;&#x5B83;&#x4EEC;&#x8FDE;&#x5728;&#x4E00;&#x8D77;&#x89E3;&#x91CA;&#xFF0C;&#x5C06;&#x7B2C;&#x4E8C;&#x884C;&#x89E3;&#x91CA;&#x4E3A;&#x7B2C;&#x4E00;&#x884C;&#x7684;&#x53C2;&#x6570;.</p>
<p>&#x63A8;&#x800C;&#x5E7F;&#x4E4B;&#xFF0C;&#x4EFB;&#x4F55;&#x8BA9;&#x89E3;&#x91CA;&#x5668;&#x4EE5;&#x8868;&#x8FBE;&#x5F0F;&#x6765;&#x5904;&#x7406;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x90FD;&#x80FD;&#x4EA7;&#x751F;&#x540C;&#x6837;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x6BD4;&#x5982;&#x4E0B;&#x9762;&#x4E09;&#x79CD;&#x5199;&#x6CD5;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> i = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>; }();
<span class="hljs-literal">true</span> &amp;&amp; <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }();
<span class="hljs-number">0</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }();
</code></pre>
<p>&#x751A;&#x81F3;&#x50CF;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x5199;&#xFF0C;&#x4E5F;&#x662F;&#x53EF;&#x4EE5;&#x7684;&#x3002;</p>
<pre><code class="lang-js">!<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
~<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
-<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
+<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
</code></pre>
<p>&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x53EA;&#x5BF9;&#x533F;&#x540D;&#x51FD;&#x6570;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x201C;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x201D;&#x3002;&#x5B83;&#x7684;&#x76EE;&#x7684;&#x6709;&#x4E24;&#x4E2A;&#xFF1A;&#x4E00;&#x662F;&#x4E0D;&#x5FC5;&#x4E3A;&#x51FD;&#x6570;&#x547D;&#x540D;&#xFF0C;&#x907F;&#x514D;&#x4E86;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF1B;&#x4E8C;&#x662F; IIFE &#x5185;&#x90E8;&#x5F62;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x53EF;&#x4EE5;&#x5C01;&#x88C5;&#x4E00;&#x4E9B;&#x5916;&#x90E8;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#x7684;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5199;&#x6CD5;&#x4E00;</span>
<span class="hljs-keyword">var</span> tmp = newData;
processData(tmp);
storeData(tmp);

<span class="hljs-comment">// &#x5199;&#x6CD5;&#x4E8C;</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> tmp = newData;
  processData(tmp);
  storeData(tmp);
}());
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5199;&#x6CD5;&#x4E8C;&#x6BD4;&#x5199;&#x6CD5;&#x4E00;&#x66F4;&#x597D;&#xFF0C;&#x56E0;&#x4E3A;&#x5B8C;&#x5168;&#x907F;&#x514D;&#x4E86;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Symbol.html" class="navigation navigation-prev " aria-label="Previous page: Symbol">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="函数的扩展.html" class="navigation navigation-next " aria-label="Next page: 函数的扩展">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"函数","level":"1.2.8","depth":2,"next":{"title":"函数的扩展","level":"1.2.8.1","depth":3,"path":"基础/函数的扩展.md","ref":"基础/函数的扩展.md","articles":[]},"previous":{"title":"Symbol","level":"1.2.7","depth":2,"path":"基础/Symbol.md","ref":"基础/Symbol.md","articles":[]},"dir":"ltr"},"config":{"plugins":["lunr","pageview-count","chapter-fold","back-to-top-button","code","hide-element","-sharing","sharing-plus","custom-favicon"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"code":{"copyButtons":true},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"favicon":"js.ico","back-to-top-button":{},"pageview-count":{},"custom-favicon":{},"sharing":{"qq":true,"all":["douban","facebook","google","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","whatsapp"],"douban":true,"facebook":true,"weibo":true,"twitter":true,"pocket":true,"google":true,"qzone":true},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Veng","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JavaScript学习","language":"zh-hans","gitbook":"*","description":"javaScript的学习笔记"},"file":{"path":"基础/函数.md","mtime":"2020-12-10T02:10:04.990Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-12-10T03:00:51.663Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

